package com.example.park2212.merchant

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.lib_base.mvvm.BaseActivity
import com.example.park2212.R
import com.example.park2212.databinding.ActivityMerchantDetailBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/merchant/MerchantDetailActivity")
class MerchantDetailActivity : BaseActivity<ActivityMerchantDetailBinding,MerchantViewModel>() {
    @Autowired
    lateinit var mid:String
    override fun initView() {
        ARouter.getInstance().inject(this)
        viewModel.getMerchantById(mid.toInt())

        binding.merappOk.setOnClickListener {
            viewModel.approve(mid.toInt())
        }

        binding.merappRefause.setOnClickListener {
            viewModel.reject(mid.toInt())
        }


    }

    override fun initData() {
        viewModel.getMerchantByIdSuccess.observe(this){
            binding.bean = it

            if (it.status == "新建"){
                binding.merdetailGroup.visibility = View.VISIBLE
                binding.merStatus.apply {
                    setText("处理中")
                }
                binding.merShenhe.setText("待处理")
            }else if (it.status == "驳回"){
                binding.merdetailGroup.visibility = View.GONE
                binding.merStatus.apply {
                    setText(it.status)
                    setBackgroundResource(R.drawable.shape_weihu)
                    setTextColor(resources.getColor(R.color.orange))
                }

                binding.merProCircle2.setBackgroundResource(R.drawable.shape_solid_orange)
                binding.merShenhe.setText(it.status)
                binding.merShTime.setText(it.processingSteps.get(1).stepTime)
            }else{
                binding.merdetailGroup.visibility = View.GONE
                binding.merStatus.apply {
                    setText(it.status)
                }

                binding.merProCircle2.setBackgroundResource(R.drawable.shape_solid_darkgreen)
                binding.merShenhe.setText(it.status)
                binding.merShTime.setText(it.processingSteps.get(1).stepTime)
            }
        }

        viewModel.approveSuccess.observe(this){
            ToastUtils.showLong("审核成功")
            finish()
        }
    }

}